package com.buer.storage.api;


import com.buer.storage.business.domain.Department;
import com.buer.storage.business.dto.DepartmentDto;
import com.buer.storage.business.service.DepartmentService;
import com.buer.storage.common.annotation.Auth;
import com.buer.storage.common.eumn.ResultEnum;
import com.buer.storage.common.utils.BaseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

//库位管理
@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Resource
    private DepartmentService departmentService;

    //增加库位
    @Auth
    @PostMapping("/add.do")
    public BaseResult add(@RequestBody DepartmentDto departmentDto) {
        if(departmentService.add(departmentDto) >0){
            //添加库位成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //添加库位成功
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //删除库位
    @Auth
    @GetMapping("/delete.do")
    public BaseResult delete(Integer departmentId) {
        if (departmentService.delete(departmentId) > 0) {
            //删除库位成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //删除库位失败
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //修改库位
    @Auth
    @PostMapping("/update.do")
    public BaseResult update(@RequestBody DepartmentDto departmentDto){
        if (departmentService.update(departmentDto)>0){
            //修改库位成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //修改库位失败
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //查询所有库位
    @Auth
    @GetMapping("/select.do")
    public BaseResult select(){
        List<Department> select = departmentService.select();
        return BaseResult.build(ResultEnum.SUCCESS,select);
    }
}
